// pages/search/search.js
let {
  getSearchList,
  getSearch
} = require("../../utils/request.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 热门搜索栏
    hotList:[],
    // 关键字
    keywords:"",
    // 搜索下拉栏
    songs:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    let res = await getSearchList();
    this.setData({
      hotList:res.data.result.hots
    })
  },
  async search(){
    let res = await getSearch(this.data.keywords)
    console.log(res);
    this.setData({
      songs:res.data.result.songs
    })
  },
  changeSearch(e){
    console.log(e.detail.value);
    if(e.detail.value==""){
      this.setData({
        keywords:"",
        songs:[]
      })
      return
    }
    this.setData({
      keywords:e.detail.value
    },()=>{
      this.search()
    })
  },
  searchHot(e){
    console.log(e);
    let hot = e.currentTarget.dataset.hot
    this.setData({
      keywords:hot
    },()=>{
      this.search() 
    })
  },
  // goInfo(e){
  //   console.log(e);
  //   let id =e.currentTarget.dataset.id
  //   wx.navigateTo({
  //     url: `/pages/topInfo/topInfo?searchId=${id}`,
  //   })
  // }
})